<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px" style="margin-bottom: 5px;font-size: 0px">
      <div class="con-container">
        <div class="lab-container">
          <label class="condition-item-title">流程名称</label>
          <el-form-item label="" prop="flowPathName" class="custom-el-form-item">
            <el-input
              v-model="queryParams.flowPathName" class="query-param"
              placeholder="请输入流程名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </div>

        <div class="btn-container">
          <el-form-item>
            <el-button type="primary" icon="el-icon-setting" size="mini" @click="conditionToggle">高级查询
            </el-button>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
                       v-hasPermi="['processNode:processNode:add']">新增
            </el-button>
            <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
                       v-hasPermi="['processNode:processNode:export']">导出
            </el-button>
            <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
                       v-hasPermi="['processNode:processNode:remove']"
            >删除
            </el-button>
          </el-form-item>
        </div>
      </div>

      <div class="toggle-container" ref="toggle-container" style="display: none;">

        <div class="condition-item">
          <label class="condition-item-title">流程key</label>
          <el-form-item label="" prop="flowPathKey">
            <el-input
              v-model="queryParams.flowPathKey" class="query-param"
              placeholder="请输入流程key"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </div>
        <div class="condition-item">
          <label class="condition-item-title">节点名称</label>
          <el-form-item label="" prop="nodeName">
            <el-input
              v-model="queryParams.nodeName" class="query-param"
              placeholder="请输入节点名称"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </div>
        <div class="condition-item">
          <label class="condition-item-title">节点审批角色</label>
          <el-form-item label="" prop="nodeRole">
            <el-input
              v-model="queryParams.nodeRole" class="query-param"
              placeholder="请输入节点审批角色"
              clearable
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </div>
        <div class="condition-item">
          <label class="condition-item-title">节点状态 </label>
          <el-form-item label="" prop="nodeStatus">
            <el-select v-model="queryParams.nodeStatus" placeholder="--全部--" clearable size="small" class="query-param">
              <el-option label="请选择字典生成" value=""/>
            </el-select>
          </el-form-item>
        </div>
      </div>
    </el-form>

    <el-table ref="table" v-loading="loading" @sort-change="changeTableSort" stripe @row-dblclick="handleDoubleClick"
              :height="tableHeight" :header-cell-style="{fontSize:'14px', fontWeight:'500'}"
              :data="processNodeList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="序号" type="index" width="60" align="left">
        <template slot-scope="scope">
          <span>{{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="流程名称" align="left" prop="flowPathName" sortable :render-header="renderHeader"/>
      <el-table-column label="流程key" align="left" prop="flowPathKey" sortable :render-header="renderHeader"/>
      <el-table-column label="节点名称" align="left" prop="nodeName" sortable :render-header="renderHeader"/>
      <el-table-column label="节点审批角色" align="left" prop="nodeRole" :formatter="roleFormatter" sortable :render-header="renderHeader"/>
      <el-table-column label="节点状态" align="left" prop="nodeStatus" sortable :render-header="renderHeader">
        <template slot-scope="scope">
          <el-switch
            v-model="scope.row.nodeStatus"
            :active-value = "0"
            :inactive-value = "1"
            @change="handleStatusChange(scope.row)"
          ></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="节点顺序" align="left" prop="nodeSort" sortable :render-header="renderHeader"/>
      <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="180">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
            v-hasPermi="['processNode:processNode:query']"
          >详情
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['processNode:processNode:edit']"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['processNode:processNode:remove']"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      :page-sizes="pageList"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 新增或修改流程配置对话框 -->
    <el-dialog :visible.sync="open" :close-on-click-modal="false" class="customForm _baseForm_small"
               @opened="openDialog">
      <div slot="title">
        <span><i :class="dialogIcon"></i></span>
        <span> {{ title }}</span>
      </div>
      <div class="processNode-body"></div>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <div class="sub-project">
          <div class="sub-title">
            <div class="sub-title-name">基本信息</div>
          </div>
          <div class="sub-body">
            <el-row>
              <el-col :span="24">
                <el-form-item label="流程名称" prop="flowPathName" v-if="!readOnly">
                  <el-input v-model="form.flowPathName" placeholder="请输入流程名称"/>
                </el-form-item>
                <el-form-item label="流程名称：" prop="flowPathName" v-if="readOnly" class="custom-form-item">
                  {{ form.flowPathName }}
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="流程key" prop="flowPathKey" v-if="!readOnly">
                  <el-input v-model="form.flowPathKey" placeholder="请输入流程key"/>
                </el-form-item>
                <el-form-item label="流程key：" prop="flowPathKey" v-if="readOnly" class="custom-form-item">
                  {{ form.flowPathKey }}
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="节点名称" prop="nodeName" v-if="!readOnly">
                  <el-input v-model="form.nodeName" placeholder="请输入节点名称"/>
                </el-form-item>
                <el-form-item label="节点名称：" prop="nodeName" v-if="readOnly" class="custom-form-item">
                  {{ form.nodeName }}
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="节点审批角色" prop="nodeRole" v-if="!readOnly">
                  <!--              <el-input v-model="form.nodeRole" placeholder="请输入节点审批角色" />-->
                  <el-select v-model="form.nodeRole" placeholder="--全部--" clearable size="small" style="width: 100%"
                             class="custom-form-item">
                    <el-option
                      v-for="item in roles"
                      :key="item.roleKey"
                      :label="item.roleName"
                      :value="item.roleKey"
                    />
                  </el-select>
                </el-form-item>
                <el-form-item label="节点审批角色：" prop="nodeRole" v-if="readOnly" class="custom-form-item">
                  {{ roleFormatter(form) }}
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="节点状态" prop="nodeStatus" v-if="!readOnly">
                  <el-radio-group v-model="form.nodeStatus" class="customRadio form-item">
                    <el-radio label="0">开启</el-radio>
                    <el-radio label="1">关闭</el-radio>
                  </el-radio-group>
                </el-form-item>
                <el-form-item label="节点状态 ：" prop="nodeStatus" v-if="readOnly" class="custom-form-item">
                  {{nodeStatusFormat(form)}}
                </el-form-item>
              </el-col>
              <el-col :span="24">
                <el-form-item label="节点顺序" prop="nodeSort" v-if="!readOnly">
                  <el-input-number v-model="form.nodeSort" placeholder="请输入节点顺序" :default="0" :min="0" :max="100"/>
                  <label style="margin-left: 1vw;font-size: 1vh;color: red">流程节点从0开始，执行顺序0-1-2</label>
                </el-form-item>
                <el-form-item label="节点顺序 ：" prop="nodeSort" v-if="readOnly" class="custom-form-item">
                  {{ form.nodeSort }}   <label style="margin-left: 1vw;font-size: 1vh;color: red">流程节点从0开始，执行顺序0-1-2</label>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <div v-if="operationType != 3">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
        <div v-if="operationType == 3">
          <el-button type="primary" @click="cancel">关 闭</el-button>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import processNode from "./processNode";

export default {
  ...processNode
}
</script>
<style scoped>
.form-item {
  width: 100%;
}
</style>
